﻿import request from '@/utils/request'

// 查询文章列表
export function bookLists(query) {
    return request({
        url: '/book/bookList',
        method: 'get',
        headers: {
          isToken: false
        },
        params: query
    })
}

// 查询平台推荐文章列表
export function bookListsIntro(query) {
  return request({
      url: '/book/bookListsIntro',
      method: 'get',
      headers: {
        isToken: true
      },
      params: query
  })
}

// 查询猜你喜欢文章列表
export function bookLikeLists(query) {
  return request({
      url: '/book/bookLikeList',
      method: 'get',
      headers: {
        isToken: true
      },
      params: query
  })
}

//获取书籍内容详情
export function getBook(bookId) {
    return request({
        url: '/book/' + bookId,
        headers: {
          isToken: true
        },
        method: 'get'
    })
}

// 更新书籍浏览量
export function updateBookView(id) {
  return request({
    url: '/book/updateBookView',
    method: 'put',
    headers: {
      isToken: true
    },
    data: { "id": id }
  })
}

// 查询书籍章节
export function getEssayListById(query) {
  return request({
    url: '/book/getEssayListById',
    method: 'get',
    headers: {
      isToken: true
    },
    params: query
  })
}

// 查询热门书籍
export function getHotBookAll(query) {
  return request({
    url: '/book/getHotBookAll',
    method: 'get',
    headers: {
      isToken: true
    },
    params: query
  })
}

// 查询高分书籍
export function getHighScoreBookAll(query) {
  return request({
    url: '/book/getHighScoreBookAll',
    method: 'get',
    headers: {
      isToken: true
    },
    params: query
  })
}

// 查询书籍评分
export function getBookRating(id) {
  return request({
    url: `/book/getBookRating/${id}`,
    method: 'get',
    headers: {
      isToken: true
    },
  })
}

// 书籍评分
export function bookRating(userId, bookId,rating) {
  return request({
      url: '/book/bookRating',
      method: 'post',
      headers: {
          isToken: true
      },
      data: { 'userId': userId, 'bookId': bookId,"rating":rating }
  })
}

// 查询用户对某本书籍的收藏状态
export function getCollectState(userId,bookId) {
  return request({
      url: '/book/getCollectState',
      method: 'get',
      headers: {
          isToken: true
      },
      params: { "userId": userId,"bookId":bookId }
  })
}

// 收藏书籍
export function collectBook(userId, bookId) {
  return request({
      url: '/book/collectBook',
      method: 'post',
      headers: {
          isToken: true
      },
      data: { 'userId': userId, 'bookId': bookId }
  })
}

// 收藏书籍
export function deleteCollectBook(userId, bookId) {
  return request({
      url: '/book/deleteCollectBook',
      method: 'delete',
      headers: {
          isToken: true
      },
      params: { 'userId': userId, 'bookId': bookId }
  })
}
